<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$this->display();
    }
    public function articleList(){
        $list = M('article')->select();
        $this->assign('articlelist',$list);
    	$this->display();
    }
    public function addArticle(){
    	$this->display();
    }
    public function editArticle($id){
        $field = M('article')->find($id);  
        $this->assign('field',$field);
        $this->display();
    }
    public function add(){
        $data = array();
        $res = array(); 
        $data['title'] = I("post.title",'','trim');
        $data['keywords'] = I("post.keywords",'','trim');
        $data['description'] = I("post.description",'','trim');
        $data['article'] = I("post.article");
        $data['click'] = 0;
        $res['code'] = 1;
        $res['msg'] = "添加成功";
        if(!M("article")->add($data)){
            $res['code'] = 0;
            $res['msg'] = "添加失败";
        };
        $this->ajaxReturn($res);
    }
    public function edit(){
        $data = array();
        $res = array();
        $data['id'] = I("post.id",'','trim');
        $data['title'] = I("post.title",'','trim');
        $data['keywords'] = I("post.keywords",'','trim');
        $data['description'] = I("post.description",'','trim');
        $data['article'] = I("post.article");
        $data['click'] = 0;
        $res['code'] = 1;
        $res['msg'] = "修改成功";
        if(!M("article")->save($data)){
            $res['code'] = 0;
            $res['msg'] = "修改失败";
        };
        $this->ajaxReturn($res);
    }
    public function main(){
    	echo "这里是Main方法";
        $this->display();
    }
}